﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

using Gift.DAL;
using Gift.Model;


namespace WebSite.admin.product
{
    public partial class goodsCompanyProcess : BaseAdmin
    {
        readonly dalGoodsCompany theGoodsCompany = new dalGoodsCompany();
        readonly dalGoodsCompanyPic theGoodsCompanyPic = new dalGoodsCompanyPic();
        readonly DALGoods theGoods = new DALGoods();
        readonly DALAdminLogin theAdminLogin = new DALAdminLogin();
        readonly DALShoppic theShoppic = new DALShoppic();
        tbGoodsCompany oGoodsCompany;
        tbAdminlogin oAdminLogin;
        tbGoods oGoods;
        DB_Shoppic oShoppic;


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

            }
        }

        void BuildForm()
        {
            oGoodsCompany = theGoodsCompany.GetModel(int.Parse(Request.QueryString["gid"]));
            this.ddlIsProcess.SelectedValue = oGoodsCompany.checkStates.ToString();
            
        }



        protected void btnSaveRefresh_Click(object sender, EventArgs e)
        {
            oGoodsCompany = theGoodsCompany.GetModel(int.Parse(Request.QueryString["gid"]));
            oGoodsCompany.checkStates = int.Parse(this.ddlIsProcess.SelectedItem.Value);
            oAdminLogin = theAdminLogin.GetModel(int.Parse(base.AdminUserId));
            StringBuilder sCon = new StringBuilder();
            sCon.Append(oAdminLogin.AdminName + "进行了处理--");
            if (this.ddlIsProcess.SelectedItem.Value == "1")
            {
                sCon.Append("修改状态为通过审核,");
               
            }
            if (this.ddlIsProcess.SelectedItem.Value == "2")
            {
                sCon.Append("修改状态为未通过审核,");

            }
            sCon.Append(this.txtReplay.Text.Trim());
            oGoodsCompany.processContent = string.IsNullOrEmpty(oGoodsCompany.processContent) ? "" + sCon.ToString()  : oGoodsCompany.processContent + ";" + sCon.ToString();

            theGoodsCompany.Update(oGoodsCompany);
            if (this.ddlIsProcess.SelectedItem.Value == "1")
            {
                oGoods = new tbGoods();
                oGoods.addAdminId = int.Parse(base.AdminUserId);
                oGoods.addTime = DateTime.Now;
                oGoods.AllowAllCard = false;
                oGoods.bigPic = oGoodsCompany.smallPic;
                oGoods.smallPic = oGoodsCompany.smallPic;
                oGoods.CompanyId = oGoodsCompany.companyId;
                oGoods.goodsCode = oGoodsCompany.goodsCode;
                oGoods.goodsContent = oGoodsCompany.goodsContent;
                oGoods.goodsName = oGoodsCompany.goodsName;
                oGoods.typeId = oGoodsCompany.typeId;
                oGoods.brandId = oGoodsCompany.brandId;
                oGoods.goodsOrder = 0;
                oGoods.instruction = oGoodsCompany.instruction;
                oGoods.visible = true;
                int gId = theGoods.Add(oGoods);

                DataTable dt =  theGoodsCompanyPic.GetList(" proid= " + oGoodsCompany.goodsId.ToString()).Tables[0];
                foreach(DataRow dr in dt.Rows)
                {
                  oShoppic = new DB_Shoppic();
                  oShoppic.picurl = dr["picurl"].ToString();
                  oShoppic.proid = gId;
                  theShoppic.Add(oShoppic);
                }
            }
            ExtAspNet.PageContext.RegisterStartupScript(ExtAspNet.ActiveWindow.GetHidePostBackReference());
        }
    }
}